<template>
    <div>
        <h1>会员显示</h1>
        姓名<input type="text" v-model="info.names">
        年龄 <input type="text" v-model="info.con">-<input type="text" v-model="info.end">
        会员等级 <input type="text" v-model="info.dj">
        <input type="button" value="查询" @click="getlist">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>Id</td>
                    <td>会员名称</td>
                    <td>头像</td>
                    <td>会员等级</td>
                    <td>年龄</td>
                    <td>操作</td>

                </tr>

                <tr v-for="itme in data.list":key="itme.Id">
                    <td>{{ itme. Id}}</td>
                    <td>{{ itme. HyName}}</td>
                    <td><img :src="itme.Img" width="60" height="60" ></td>
                    <td>{{ itme. GjId}}</td>
                    <td>{{ itme. Age}}</td>
                    <td>
                        <input type="button" value="禁用" @click="del(itme.Id)">
                        <input type="button" value="修改" @click="xg(itme.Id)">
                    </td>
                </tr>
            </tbody>
        </table>
        <span><b>共{{ data.totalcount }}条</b></span>
        <span><b>每页{{ info.pagesize }}条</b></span>
        <span><b>共 {{ info.pageindex }} /{{ data.totalpage }}页</b></span>
        <input type="button" value="首页" @click="gopage(1)">
        <input type="button" value="上一页" @click="gopage(info.pageindex-1)">
        <span v-for="itme in data.totalpage":key="itme.pageindex" >{{ itme }}</span>
        <input type="button" value="下一页" @click="gopage(info.pageindex+1)">
        <input type="button" value="尾页" @click="gopage(data.totalpage)">
    </div>
</template>

<script setup lang="ts">
import {ref, reactive,onMounted} from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
const router=useRouter();
const route=useRoute();
let info:any=reactive({
  names:'',
  con:'',
  end:'',
  dj:'',
  pageindex:1,
  pagesize:2,
})
let data:any=reactive({
    list:[],
    totalcount:0,
    totalpage:0
})
onMounted(()=>{
    getlist();
})
//================禁用=================
const del=(id:any)=>{
    axios({
        url:'/api/HY/JY',
        method:'delete',
        params:{id:id}
    })
    .then((res)=>{
        if(res.data>0)
    {
        alert("禁用成功");
        getlist();
        return;
    }
    else
    {
        alert("禁用失败");
        return;
    }
    })
    .catch((err)=>{
        console.log(err);
        
    })

}
//================修改=================
const xg=(id:any)=>{
    router.push({
        path:'/hyxg',
        query:{id:id}
    })
}

//================显示=================
const getlist=()=>{
    axios({
        url:'/api/HY/GetDJShow',
        method:'get',
        params:info
    })
    .then((res)=>{
        console.log(res);
        Object.assign(data,res.data)
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
//================分页=================
const show=()=>{
    info.pageindex=1,
    getlist();
}
const gopage=(num:any)=>{
    if(num<1)
{
    info.pageindex=1;
    return;
}
if(info.pageindex>data.totalcount)
{
    info.pageindex>data.totalcount;
    return;
}
info.pageindex=num;
getlist();
}
</script>

<style scoped>

</style>